﻿using System;
using System.Data;
using System.Configuration;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections;
using Dcms.BLL;
using Dcms.Common;
using Dcms.Model;
using WebApp.AppCode;

public partial class Manage_Modle_Link_ListLink : System.Web.UI.Page
{
    public CompetenceLib CL = new CompetenceLib();
    Dcms_LinkBLL lBll = new Dcms_LinkBLL();

    /// <summary>
    /// 页面加载
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        CL.IsLogin();
        try
        {
            if (CL.IsDelete(Convert.ToInt32(strCateID)) == false)
            {
                btnDelete.Visible = false;
            }
            if (!IsPostBack)
            {
                int Cate_ID = DcmsRequest.GetQueryInt("CatID", 0);
                if (Cate_ID > 0)
                {
                    this.hidAmount.Value = lBll.GetDataCount(("select count(*) from Dcms_Link Where Link_CateId=" + Cate_ID).ToString());
                    this.hidSql.Value = "select * from Dcms_Link Where Link_CateId=" + Cate_ID + " Order by Link_ID desc";
                    ReBinder(1);
                }
            }
        }
        catch (Exception ex)
        {
            Log.LogHandler.LogError("Manage_Modle_Link_ListLink.Page_Load", ex);
            throw ex;
        }	
    }
    protected void BindRpt(object sender, PagingEventArgs e)
    {
        this.ReBinder(e.pageIndex);
    }

    private void ReBinder(int PageIndex)
    {
        this.repIntor.DataSource = lBll.GetDataListByPage(this.hidSql.Value, PageIndex, 10);
        this.repIntor.DataBind();
        pagingctrl.InitPc(Convert.ToInt32(this.hidAmount.Value), PageIndex, 10);
    }

    public String GetStrLeng(String Str)
    {
        return Utils.GetSubString(Str, 30, "...");
    }
    public String FormatDateTimeMy(String Str)
    {
        return Convert.ToDateTime(Str).ToString("yyyy-MM-dd");
    }

    protected void repnew_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            LinkButton HypDelete = (LinkButton)e.Item.FindControl("HypDelete");
            if (CL.IsDelete(Convert.ToInt32(strCateID)))
            {
                HypDelete.Attributes.Add("onclick", "return confirm('确定要删除该记录吗？');");
            }
            else
            {
                HypDelete.Text = "<img src=\"../../images/ico_del_1.gif\" width=\"16\" height=\"16\" alt=\"您无权限使用删除\" />";
                HypDelete.Enabled = false;
            }
            LinkButton btnEdit = (LinkButton)e.Item.FindControl("btnEdit");
            if (CL.IsEdit(Convert.ToInt32(strCateID)) == false)
            {
                btnEdit.Text = "<img src=\"../../images/edit_1.gif\" width=\"16\" height=\"16\" alt=\"您无权限使用编辑\"/>";
            }
        }
    }

    protected void repnew_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            if (e.CommandName == "delete")
            {
                int Cate_ID = DcmsRequest.GetQueryInt("CatID", 0);
                lBll.DeleteModelByID(Convert.ToInt32(((HiddenField)e.Item.FindControl("hidID")).Value));
                Response.Redirect(Request.Url.ToString());
            }
            else if (e.CommandName == "edit")
            {
                Response.Redirect(((HiddenField)e.Item.FindControl("hidEditUrl")).Value);
            }
        }
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        int Cate_ID = DcmsRequest.GetQueryInt("CatID", 0);
        string AllID = DcmsRequest.GetFormString("ID");
        if (AllID.Trim().Length > 0)
        {
            lBll.DeleteAllCheck(AllID);
            Response.Redirect(Request.Url.ToString()); 
        }
        else
        {
            Jscript.AlertAndBack("没有选中项");
        }
    }
    protected void btnPass_Click(object sender, EventArgs e)
    {
        int Cate_ID = DcmsRequest.GetQueryInt("CatID", 0);
        string AllID = DcmsRequest.GetFormString("ID");
        if (AllID.Trim().Length > 0)
        {
            lBll.UpdateState(AllID, 1);
            Response.Redirect(Request.Url.ToString()); 
        }
        else
        {
            Jscript.AlertAndBack("没有选中项");
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        int Cate_ID = DcmsRequest.GetQueryInt("CatID", 0);
        string AllID = DcmsRequest.GetFormString("ID");
        if (AllID.Trim().Length > 0)
        {
            lBll.UpdateState(AllID, 0);
            Response.Redirect(Request.Url.ToString()); 
        }
        else
        {
            Jscript.AlertAndBack("没有选中项");
        }
    }


    public string strCateID
    {
        get
        {
            return Request.QueryString["CatID"] + "";
        }
    }
}
